package com.easygoods.controller;

import com.bestvike.stone.spring.controller.BaseController;
import com.easygoods.service.TinyUrlService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by 许崇雷 on 2019-02-12.
 */
@RestController
public class TinyUrlController extends BaseController {
    public static final String URL = "/t";
    @Autowired
    private TinyUrlService tinyUrlService;

    // 短 url 解析,跳转
    @GetMapping("/t/{tiny}")
    public void getSession(@PathVariable(value = "tiny", required = false) String tiny, HttpServletResponse response) throws IOException {
        final String url = this.tinyUrlService.tinyToUrl(tiny);
        response.sendRedirect(url);
    }
}
